﻿// See https://aka.ms/new-console-template for more information

using System.Diagnostics;

using (var httpclient = new HttpClient())
{
    string url = "https://localhost:7120/WeatherForecast/ConsumeInventory";
    //var response = await httpclient.PostAsync(url, null);
    //var result=await response.Content.ReadAsStringAsync();
    int i = 1;
    List<Task<HttpResponseMessage>> tasks = new List<Task<HttpResponseMessage>>();
    while (i <= 120)
    {
        tasks.Add(httpclient.PostAsync(url, null));
        i++;
    }
    Stopwatch stopwatch = Stopwatch.StartNew();
    stopwatch.Start();
    var response = await Task.WhenAll(tasks);
    stopwatch.Stop();
    Console.WriteLine(stopwatch.ElapsedMilliseconds);
    int result1 = 0, result2 = 0;
    foreach (var res in response)
    {
        var result=await res.Content.ReadAsStringAsync();
        if (result == "1")
        {
            result1++;
        }
        else
        {
            result2++;
        }
    }
    Console.WriteLine($"成功：{result1}   失败{result2}");
}